<template>
  <div class="crm-page home-page">
    <div class="page-header">回款详情</div>
    <div class="page-content transparent">
      <div class="page-card">
        <div class="card-title">
          <el-button class="back-btn" size="medium" type="text" icon="el-icon-back" @click="goMainBack()">返回</el-button>
        </div>
        <div class="page-card-content">
          <div class="item-title" style="margin-top:20px">
            基本信息
          </div>
          <div class="card-item">
            <el-row :gutter="10">
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">回款单号：</span>
                <span class="content">{{ data.no }}</span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">客户名：</span>
                <span class="content">
                  <span class="app-link" @click="gotoMainPage('customer/info',{id:data.customerId})">  {{ data.customerName }}</span>
                </span>
              </el-col>
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">合同：</span>
                <span class="content">
                  <span class="app-link" @click="gotoMainPage('contract/info',{id:data.contractId})">  {{ data.contractNum }}</span>
                </span>
              </el-col>
              <!-- <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">订单号：</span>
                <span class="content">{{ data.name }}</span>
              </el-col> -->
              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">单据状态：</span>
                <span class="content">{{ data.statusText }}</span>
              </el-col>

              <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="4">
                <span class="title">所有人：</span>
                <span class="content">{{ data.owner }}</span>
              </el-col>
            </el-row>
          </div>
        </div>
      </div>
      <!-- <div class="page-card">
        <PayStatusLine v-if="data.status" :status="data.status" @change="handleChangeStatus" />
      </div> -->
      <el-row :gutter="20">
        <el-col :xs="24" :sm="24" :md="24" :lg="14" :xl="14">
          <div class="page-card">
            <div class="page-card-content">
              <div class="item-title no-border">
                <el-tabs v-model="activeTabName">
                  <el-tab-pane label="详细信息" name="1" />
                  <el-tab-pane label="回款详情" name="2" />
                  <el-tab-pane v-if="data.status>1" label="审批流程" name="3" />
                </el-tabs>
              </div>
              <div v-if="activeTabName==='1'" class="card-item">
                <el-row :gutter="10">
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">客户名：</span>
                    <span class="content">{{ data.customerName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">所有人：</span>
                    <span class="content">{{ data.owner }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">合同编号：</span>
                    <span class="content">{{ data.contractNum }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">合同金额（元）：</span>
                    <span class="content">{{ data.contractAmount | formatMoney }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">回款日期：</span>
                    <span class="content">{{ formatTime( data.paymentDate,'YYYY-MM-DD') }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">回款总金额（元）：</span>
                    <span class="content">{{ data.amount |moneyFormat }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">付款方式：</span>
                    <span class="content">
                      {{ data.paymentModeText }}
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">备注：</span>
                    <span class="content">
                      {{ data.remark }}
                    </span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建人：</span>
                    <span class="content">{{ data.createName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改人：</span>
                    <span class="content">{{ data.updateName }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">创建时间：</span>
                    <span class="content">{{ formatTime(data.createTime) }}</span>
                  </el-col>
                  <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
                    <span class="title">上次修改时间：</span>
                    <span class="content">{{ formatTime(data.updateTime) }}</span>
                  </el-col>
                </el-row>
              </div>
              <div v-if="activeTabName==='2'" class="card-item">
                <el-table
                  border
                  :data="data.list"
                >
                  <el-table-column
                    type="index"
                    width="55"
                    size="mini"
                    align="center"

                    label="序号"
                  />
                  <el-table-column show-overflow-tooltip prop="orderNo" width="150" label="项目/订单编号">
                    <template slot-scope="{row}">
                      {{ row.orderNo }}
                    </template>
                  </el-table-column>
                  <el-table-column show-overflow-tooltip prop="orderNo" width="120" align="right" label="订单金额（元）">
                    <template slot-scope="{row}">
                      {{ row.orderAmount| moneyFormat }}
                    </template>
                  </el-table-column>
                  <el-table-column align="left" prop="paymentPlanNo" width="150" label="计划回款单号" />
                  <el-table-column align="left" prop="paymentPlaneDate" width="150" label="计划回款日期">
                    <template slot-scope="{row}">
                      {{ formatTime(row.paymentPlaneDate,'YYYY-MM-DD') }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="paymentPlaneAmount" align="right" width="150" label="计划回款金额（元）">
                    <template slot-scope="{row}">
                      {{ row.paymentPlaneAmount | moneyFormat }}
                    </template>
                  </el-table-column>
                  <el-table-column align="right" prop="amount" width="150" label="本次回款金额（元）">
                    <template slot-scope="{row}">
                      {{ row.amount | moneyFormat }}
                    </template>
                  </el-table-column>
                  <!-- <el-table-column prop="surplusAmount" width="150" align="right" label="剩余金额（元）">
                    <template slot-scope="{row}">
                      {{ row.surplusAmount | moneyFormat }}
                    </template>
                  </el-table-column> -->
                  <el-table-column align="left" prop="remark" width="150" show-overflow-tooltip label="备注">
                    <!-- <template slot-scope="{row}">
                      <el-input v-model="row.remark" style="width:100%" />
                    </template> -->
                  </el-table-column>
                </el-table>
              </div>
              <div v-if="activeTabName==='3'" class="card-item">
                <div class="approve-status">
                  <span>状态：{{ data.statusText }}</span>
                </div>
                <ApproveProcess type="9" :ext-id="data.id" />
              </div>
            </div>
          </div>
          <InvoiceCard
            v-if="data.customerId"
            type="9"
            :contract-id="data.contractId"
            :contract-no="data.contractNum"
            :customer-id="data.customerId"
            :customer-name="data.customerName"
          />

        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="10" :xl="10">
          <ActivityCard
            :data="{
              name:data.customerName,
              relateName:data.no,
              relateId:data.id
            }"
            :type="9"
            @change="handleCardChange"
          />
          <ActivityListCard v-if="data.id" ref="listCard" :relateid="data.id" :type="9" />
        </el-col>

      </el-row>

    </div>
  </div>
</template>
<script>

// import PayStatusLine from '@/components/PayStatusLine'
import ActivityCard from '@/components/ActivityCard'
import ActivityListCard from '@/components/ActivityListCard'
import InvoiceCard from '@/components/InfoCard/InvoiceCard'
import ApproveProcess from '@/components/Approve/ApproveProcess'

import { getPay, updatePayStatus } from '@/api/pay'

import { getEnumText, paymentStatus, payMethods } from '@/utils/enums'
import { formatTime } from '@/utils/tools'
export default {
  name: 'CustomerInfo',
  components: { ActivityCard, ActivityListCard, InvoiceCard, ApproveProcess },
  data() {
    return {
      activeTabName: '1',
      data: {

        statusText: ''
      }

    }
  },
  mounted() {
    const id = this.$route.query.id
    getPay({ id }).then(res => {
      this.data = res
      this.data.list = res.list || []
      this.data.statusText = getEnumText(paymentStatus, this.data.status)
      // this.data.amount = BigNumber(this.data.amount || 0).toFixed(4)
      this.data.paymentModeText = getEnumText(payMethods, this.data.paymentMode)
      // this.data.contractAmount = BigNumber(this.data.contractAmount || 0).toFixed(4)
    })
  },
  methods: {
    formatTime,
    handleCardChange() {
      this.$refs.listCard.refresh()
    },
    handleChangeStatus(v) {
      const data = {
        id: this.data.id,
        status: v
      }
      updatePayStatus(data).then(res => {
        this.data.status = v
        this.data.statusText = getEnumText(paymentStatus, this.data.status)

        this.$message({
          type: 'success',
          message: '修改成功'
        })
      }).catch(ex => {
        this.$message({
          type: 'error',
          message: ex.message || '修改失败'
        })
      })
    }

  }
}
</script>

